﻿using MCUPackage;
using MCUPackage.Utils;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SxPackages.STC32G.Models
{
	[Serializable]
	class UART3Options : USARTOptionBase
	{
		private UART3Pins mPins = UART3Pins.RxD_P00_TxD_P01;
		[DisplayName("使用引脚"),
		DefaultValue(UART3Pins.RxD_P00_TxD_P01),
		Description("本串口使用的引脚设置")]
		public UART3Pins Pins
		{
			get => mPins;
			set
			{
				if (value != mPins)
				{
					if (SwitchPins(value, mPins))
					{
						mPins = value;
					}
				}
			}
		}

		protected override void SetPins(String[] aPins)
		{
			var opt = mParent.SetPinPurpose(aPins[0], PinPurpose.UART3_RCV);
			opt.Mode = GPIOMode.Standard;
			opt.Speed = GPIOSpeed.Fast;
			opt.EnableUp = true;
			opt = mParent.SetPinPurpose(aPins[1], PinPurpose.UART3_SND);
			opt.Mode = GPIOMode.Push;
			opt.Speed = GPIOSpeed.Fast;
		}

		public UART3Options(STC32GQFP64 aParent) : base(aParent)
		{
			Id = 3;
			mUsePins = TemplateHelper.GetPins(mPins);
		}
	}
}
